home *** CD-ROM | disk | FTP | other *** search
- /* EasyCODE(C++) V5.1 02.03.1995 13:37:54 */
- /* EasyCODE O
- If=vertical
- LevelNumbers=no
- LineNumbers=no
- ScreenFont=Courier New,,80,9220,-11,0,400,0,0,0,0,0,0,3,2,1,49
- PrinterFont=Courier New,,80,17414,-34,0,400,0,0,0,0,0,0,3,2,1,49
- LastLevelId=445 */
-
- /* EasyCODE ( 1
- cob2spx.c */
-
- /* EasyCODE ( 377
- Includes, Constants */
- /* INCLUDES */
- #include "convio.h"
- #include "conv.h"
- #include "tabledef.h"
- #include <string.h>
- /* EasyCODE - */
- /* CONSTANTS */
- #define MAX_DELIMITERLEN 2
- #define MAX_ADDTEXTLEN 32
- #define MAX_DEPTH 64
- #define MAX_LEVEL 64
-
- #define USAGEMSG "Usage: %s inputfile outputfile [/l=<int>] [/c] [/s=<divisions>]\n"
- #define SPACES1 " "
- #define SPACES2 " "
- #define SPACES3 " "
- #define L_OPT_LEN 2 /* max length of string in level option */
- #define S_OPT_LEN 4 /* max length of string in suppress option */
-
- #define ERR_TEXT1 "Keyword expected "
- #define ERR_TEXT2 "Unexpected EOF "
- #define ERR_TEXT3 "Keyword is not a valid COBOL keyword "
- #define ERR_TEXT4 "Maximum depth of nested constructs reached "
- /* EasyCODE ) */
-
- /* EasyCODE ( 126
- check_parms */
-
- /* EasyCODE F */
- void check_parms( int argc, char *argv[], int *ip, int *op,
- int* maxlevel, BOOL* comment, BOOL* divisions )
-
-
- // Parameter check.
- // Mandatory are Input and Output file. 3 Options are possible
- // /l=<int> .... Segment/level depth
- // between 0 and 99
- // /c .... Comments only
- // /s=<...> .... Suppress divisions
- // Combination of i,e,d,p
- // (case-insensitive)
- // Order of arguments does not matter, only input file has to be
- // before output file stehen. Options are case-insensitive,
- // '-' may be used instead of '/'.
- {
- int i;
- int len;
- int lp = -1; /* Position of option l in parameter string */
- int cp = -1; /* Position of option c in parameter string */
- int sp = -1; /* Position of option s in parameter string */
- char *eptr; /* End pointer for strtol() */
- if ((argc < 3)||(argc > 6)
- /* Number of arguments less than 3 or greater than 6 */)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- for (i=1;i<argc;i++
- /* process all arguments */)
- {
- if ((*argv[i] == '/')||(*argv[i] == '-')
- /* If Option (i.e. starting with '/' or '-' */)
- {
- switch (tolower(*(argv[i]+1))
- /* Which option ? */)
- {
- case 'l'
- /* Level option */:
- if (lp < 0
- /* first 'l' option */)
- {
- lp = i;
- /* Get position (=index) */
- }
- else
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- break;
- case 'c'
- /* Comment option */:
- if (cp < 0
- /* First 'c' option */)
- {
- cp = i;
- /* Get position (=index) */
- }
- else
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- break;
- case 's'
- /* Suppress option */:
- if (sp < 0
- /* First 's' option */)
- {
- sp = i;
- /* Get position (=index) */
- }
- else
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- break;
- default:
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- break;
- }
- }
- else
- {
- if (*ip < 0
- /* Input file not given yet */)
- {
- *ip = i;
- /* Get position (=index) */
- }
- else
- {
- if (*op < 0
- /* Output file not given yet */)
- {
- *op = i;
- /* Get position (=index) */
- }
- else
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- }
- }
- }
- if ((*ip < 0)||(*op < 0)
- /* No input file or output file given */)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- else
- {
- if (strcmp(argv[*ip],argv[*op])==0
- /* Input file and Output file identical */)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- }
- if (lp > 0
- /* 'l' option given */)
- {
- if (*(argv[lp]+2) != '='
- /* Third character not '=' */)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- else
- {
- if (strlen(argv[lp]) > L_OPT_LEN + 3
- /* 'l' string too long */)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- else
- {
- /* Convert string to number */
- *maxlevel = (int) strtol( (argv[lp]+3), &eptr, 10 );
- if ((*eptr != '\0') || (eptr == (argv[lp]+3))
- /* String contains other characters than numbers*/)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- }
- }
- }
- else
- {
- /* No 'l' option */
- }
- if (cp > 0
- /* 'c' option given */)
- {
- if (strlen(argv[cp]) > 2
- /* 'c' option too long */)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- else
- {
- /* Set comment flag */
- *comment = TRUE;
- }
- }
- else
- {
- /* No 'c' option */
- }
- if (sp > 0
- /* 's' option given */)
- {
- if (*(argv[sp]+2) != '='
- /* Third character not '=' */)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- else
- {
- if ((len = strlen(argv[sp])) > S_OPT_LEN + 3
- /* 's' string to long */)
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- else
- {
- for (i=0;i<len-3;i++
- /* Process characters in argument string */)
- {
- switch (tolower(*(argv[sp]+3+i))
- /* Process i-th character after '=' */)
- {
- case 'i'
- /* Suppress Identification Division (=i) */:
- if (*divisions
- /* divisions[0] is TRUE */)
- {
- *divisions = FALSE;
- /* divisions[0] set to FALSE */
- }
- else
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- break;
- case 'e'
- /* Suppress Environment Division (=e) */:
- if (*(divisions+1)
- /* divisions[1] is TRUE */)
- {
- *(divisions+1) = FALSE;
- /* divisions[1] set to FALSE */
- }
- else
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- break;
- case 'd'
- /* Suppress Data Division (=d) */:
- if (*(divisions+2)
- /* divisions[2] is TRUE */)
- {
- *(divisions+2) = FALSE;
- /* divisions[2] set to FALSE */
- }
- else
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- break;
- case 'p'
- /* Suppress Procedure Division (=p) */:
- if (*(divisions+3)
- /* divisions[3] is TRUE */)
- {
- *(divisions+3) = FALSE;
- /* divisions[3] set to FALSE */
- }
- else
- {
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- break;
- default:
- /* Print usage message */
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- }
- }
- }
- }
- else
- {
- /* No 's' option */
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 18
- Set_addText */
-
- /* EasyCODE F */
- void Set_addText(BOOL omit, char* addText, char* string)
-
- // Sets variable addText;
- // addText will be placed in front of or behind
- // the next text line;
- {
- if (!omit
- /* Omit indicator is FALSE */)
- {
- strcpy(addText,string);
- /* Copy given string to addText */
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 15
- StoreText */
-
- /* EasyCODE F */
- void StoreText(FILE* stream, BOOL omit, BOOL comment,
- char* keyword, char* delimiter,
- char* addText, char* contents)
-
-
- // Writes a text line to the output file.
- // The text is written either unmodified, or suppressed
- // (comment is TRUE), modified (addText not empty);
- // or inserted (contents is empty);
- {
- int len;
- int i;
- int num; /* Contains number in numstr */
- char numstr [4]; /* Number string extracted from addText */
- char *addText2;
- /* EasyCODE - */
- addText2 = malloc((MAX_ADDTEXTLEN+1)*sizeof(char));
- /* Allocate memory */
- if (!omit
- /* Omit indicator is FALSE */)
- {
- if (comment
- /* comment is TRUE */)
- {
- // Only comment is written, plus additional text
- // created for SPX.
- if ((*contents == '/')||(*contents == '*')||(*addText != '\0')
- /* Text is comment or addText is not empty */)
- {
- if (((*contents == '/')||(*contents == '*'))&&(*addText != '\0')
- /* Text is comment and addText is not empty */)
- {
- // Comment + addText is written
- if (*addText != '<'
- /* addText does not contain a number string starting with '<' */)
- {
- // Additional text is inserted at begin of line
- if (*contents == '\0'
- /* contents is empty */)
- {
- *contents = '\n';
- *(contents+1) = '\0';
- /* newline and end-of-string are added */
- }
- /* Buffer assembled again */
- strcpy(inbuf,keyword);
- strcat(inbuf,delimiter);
- strcat(inbuf,addText);
- strcat(inbuf,contents);
- if (strcmp(addText,"USING ")==0
- /* addText contains USING */)
- {
- strcpy(addText,SPACES1);
- /* SPACES1 copied to addText */
- /* to get indent for following lines */
- }
- if (strcmp(addText,"SEARCH ")==0
- /* addText contains SEARCH */)
- {
- strcpy(addText,SPACES2);
- /* SPACES2 copied to addText */
- /* to get indent for following lines */
- }
- if (strcmp(addText,"VARYING ")==0
- /* addText contains VARYING */)
- {
- strcpy(addText,SPACES3);
- /* SPACES3 copied to addText */
- /* to get indent for following lines */
- }
- if (!((strcmp(addText,SPACES1)==0)||
- (strcmp(addText,SPACES2)==0)||
- (strcmp(addText,SPACES3)==0))
-
- /* addText contains neither SPACES1 nor SPACES2 nor SPACES3 */)
- {
- strcpy(addText,"");
- /* Clear addText */
- }
- }
- else
- {
- // addText to be written at the end of the last
- // comment line of the construct header
- /* EasyCODE - */
- // addText is written if number at begin of string
- // between < and > is 1.
- /* EasyCODE - */
- strcpy(addText2,addText);
- /* EasyCODE - */
- len = 0;
- /* Length of number string initialized with 0 */
- /* EasyCODE - */
- addText2++;
- /* Set pointer to begin of number string */
- while (*addText2++ != '>'
- /* Number string not finished */)
- {
- len++;
- /* Increment length */
- }
- for (i=1;i<=len;i++
- /* While index less than length */)
- {
- numstr[i-1] = *(addText+i);
- /* Copy number to numstr */
- }
- numstr[len] = '\0';
- /* Add end-of-string */
- /* EasyCODE - */
- num = atoi(numstr);
- /* Convert string to integer */
- if (num > 1
- /* Number extracted is greater than 1 */)
- {
- // addText will be added later, only number contained
- // in addText is decremented;
- /* EasyCODE - */
- num--;
- itoa(num,numstr,10);
- /* Number is decremented and converted to a string */
- for (i=1;i<=len;i++)
- {
- *(addText+i) = numstr[i-1];
- }
- }
- else
- {
- // Extracted number is 1, addText is written
- /* EasyCODE - */
- strcpy(addText2,(addText+len+2));
- /* addText without <numstr> is copied to addText2 */
- /* EasyCODE - */
- len = strlen(contents);
- *(contents+len-1) = '\0';
- /* newline in contents is overwritten */
- /* EasyCODE - */
- /* Buffer assembled again */
- strcpy(inbuf,keyword);
- strcat(inbuf,delimiter);
- strcat(inbuf,contents);
- strcat(inbuf,addText2);
- strcat(inbuf,"\n\0");
- /* EasyCODE - */
- strcpy(addText,"");
- /* Clear addText */
- }
- }
- StoreLine(inbuf,stream);
- /* Write content of buffer to output file */
- }
- else
- {
- // There is only created text
- if (*addText != '\0'
- /* addText is not empty */)
- {
- // If not SPACES for indent after
- // USING/VARYING/SEARCH
- // addText is written;
- if ((strcmp(addText,SPACES1) != 0)&&
- (strcmp(addText,SPACES2) != 0)&&
- (strcmp(addText,SPACES3) != 0)
- /* addText is not equal SPACES1-3 */)
- {
- if (*addText == '<'
- /* First character in addText is '<' */)
- {
- // addText is written if number at begin of string
- // between < and > is 1.
- /* EasyCODE - */
- strcpy(addText2,addText);
- /* EasyCODE - */
- len = 0;
- /* EasyCODE - */
- addText2++;
- while (*addText2++ != '>')
- {
- len++;
- }
- for (i=1;i<=len;i++)
- {
- numstr[i-1] = *(addText+i);
- }
- numstr[len] = '\0';
- /* EasyCODE - */
- num = atoi(numstr);
- if (num > 1
- /* Extracted number is greaterer than 1 */)
- {
- // addText will be written later, only number contained
- // in addText is decremented;
- /* EasyCODE - */
- num--;
- itoa(num,numstr,10);
- for (i=1;i<=len;i++)
- {
- *(addText+i) = numstr[i-1];
- }
- }
- else
- {
- // addText is written
- /* EasyCODE - */
- strcpy(addText2,(addText+len+2));
- /* addText without <numstr> is copied to addText2 */
- /* EasyCODE - */
- /* Buffer assembled again */
- strcpy(inbuf,keyword);
- strcat(inbuf,delimiter);
- strcat(inbuf,addText2);
- strcat(inbuf,"\n\0");
- /* EasyCODE - */
- strcpy(addText,"");
- /* Clear addText */
- /* EasyCODE - */
- StoreLine(inbuf,stream);
- /* Write buffer to output file */
- }
- }
- else
- {
- // addText is added at begin of line
- /* EasyCODE - */
- /* Buffer assembled again */
- strcpy(inbuf,keyword);
- strcat(inbuf,delimiter);
- strcat(inbuf,addText);
- strcat(inbuf,"\n\0");
- if (strcmp(addText,"USING ")==0
- /* addText contains USING */)
- {
- strcpy(addText,SPACES1);
- /* SPACES1 copied to addText */
- /* to get indent for following lines */
- }
- if (strcmp(addText,"SEARCH ")==0
- /* addText contains SEARCH */)
- {
- strcpy(addText,SPACES2);
- /* SPACES2 copied to addText */
- /* to get indent for following lines */
- }
- if (strcmp(addText,"VARYING ")==0
- /* addText contains VARYING */)
- {
- strcpy(addText,SPACES3);
- /* SPACES3 copied to addText */
- /* to get indent for following lines */
- }
- if (!((strcmp(addText,SPACES1)==0)||
- (strcmp(addText,SPACES2)==0)||
- (strcmp(addText,SPACES3)==0))
-
- /* addText contains neither SPACES1 nor SPACES2 nor SPACES3 */)
- {
- strcpy(addText,"");
- /* Clear addText */
- }
- StoreLine(inbuf,stream);
- /* Buffer (=line) is written to the output file */
- }
- }
- }
- else
- {
- // Comment is written unmodified
- /* EasyCODE - */
- StoreLine(inbuf,stream);
- }
- }
- }
- }
- else
- {
- // comment == FALSE
- // Not only comment is written
- if (*addText != '\0')
- {
- // There is additional text, the line
- // has to be assembled again.
- if (*addText != '<')
- {
- // Additional text is inserted at begin of line
- if (*contents == '\0')
- {
- *contents = '\n';
- *(contents+1) = '\0';
- }
- strcpy(inbuf,keyword);
- strcat(inbuf,delimiter);
- strcat(inbuf,addText);
- strcat(inbuf,contents);
- /* EasyCODE - */
- // addText is cleared or modified
- if (strcmp(addText,"USING ")==0
- /* addText contains USING */)
- {
- strcpy(addText,SPACES1);
- /* SPACES1 copied to addText */
- /* to get indent for following lines */
- }
- if (strcmp(addText,"SEARCH ")==0
- /* addText contains SEARCH */)
- {
- strcpy(addText,SPACES2);
- /* SPACES2 copied to addText */
- /* to get indent for following lines */
- }
- if (strcmp(addText,"VARYING ")==0
- /* addText contains VARYING */)
- {
- strcpy(addText,SPACES3);
- /* SPACES3 copied to addText */
- /* to get indent for following lines */
- }
- if (!((strcmp(addText,SPACES1)==0)||
- (strcmp(addText,SPACES2)==0)||
- (strcmp(addText,SPACES3)==0))
-
- /* addText contains neither SPACES1 nor SPACES2 nor SPACES3 */)
- {
- strcpy(addText,"");
- /* Clear addText */
- }
- }
- else
- {
- // addText to be written at the end of the last
- // text line of the construct header
- /* EasyCODE - */
- // addText is written if number at begin of string
- // between < and > is 1.
- /* EasyCODE - */
- strcpy(addText2,addText);
- /* EasyCODE - */
- len = 0;
- /* EasyCODE - */
- addText2++;
- while (*addText2++ != '>')
- {
- len++;
- }
- for (i=1;i<=len;i++)
- {
- numstr[i-1] = *(addText+i);
- }
- numstr[len] = '\0';
- /* EasyCODE - */
- num = atoi(numstr);
- if (num > 1)
- {
- // addText is added later, only number contained
- // in addText is decremented;
- /* EasyCODE - */
- num--;
- itoa(num,numstr,10);
- for (i=1;i<=len;i++)
- {
- *(addText+i) = numstr[i-1];
- }
- }
- else
- {
- // addText2 contains addText without <numstr>
- /* EasyCODE - */
- strcpy(addText2,(addText+len+2));
- /* EasyCODE - */
- // newline '\n' in contents is overwritten
- /* EasyCODE - */
- len = strlen(contents);
- *(contents+len-1) = '\0';
- /* EasyCODE - */
- strcpy(inbuf,keyword);
- strcat(inbuf,delimiter);
- strcat(inbuf,contents);
- strcat(inbuf,addText2);
- strcat(inbuf,"\n\0");
- /* EasyCODE - */
- // Clear addText
- /* EasyCODE - */
- strcpy(addText,"");
- }
- }
- StoreLine(inbuf,stream);
- }
- else
- {
- // Line is written unmodified
- /* EasyCODE - */
- StoreLine(inbuf,stream);
- }
- }
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 16
- StoreUnchanged */
-
- /* EasyCODE F */
- void StoreUnchanged(FILE* stream, BOOL omit,
- char* keyword, char* ignore)
-
- // Writes an unmodified line to the output file,
- // if no keyword to be ignored is contained.
- {
- if (!omit
- /* Omit indicator is FALSE */)
- {
- if (strcmp(keyword,ignore) != 0
- /* Keyword does not match content of ignore */)
- {
- StoreLine(inbuf,stream);
- /* Line is written */
- }
- else
- {
- strcpy(ignore,"");
- /* Clear ignore */
- }
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 17
- StoreChanged */
-
- /* EasyCODE F */
- void StoreChanged(FILE* stream, BOOL omit,
- char* keyword, char* delimiter)
-
- // Writes a new line ( = new keyword)
- // to the output file.
- {
- if (!omit
- /* Omit indicator is FALSE */)
- {
- strcpy(inbuf,keyword);
- *(delimiter+1)='\n';
- *(delimiter+2)='\0';
- strcat(inbuf,delimiter);
- /* Copy keyword to buffer and add */
- /* delimiter, newline, and end-of-string; */
- /* EasyCODE - */
- StoreLine(inbuf,stream);
- /* Write buffer to output file */
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 19
- Set_ignore */
-
- /* EasyCODE F */
- void Set_ignore(BOOL omit, char* ignore, char* keyword)
-
- // Sets variable ignore
- {
- if (!omit
- /* Omit indicator is FALSE */)
- {
- strcpy(ignore,keyword);
- /* Copy keyword to ignore */
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 26
- Set_depth */
-
- /* EasyCODE F */
- void Set_depth(BOOL omit, int* depth, int value)
-
- /* Sets variable depth */
- {
- if (!omit
- /* Omit indicator is FALSE */)
- {
- if (value < MAX_DEPTH
- /* Given value is less than maximum depth */)
- {
- *depth = value;
- /* Depth gets value of "value" */
- }
- else
- {
- /* Print error message */
- err_msg(0,ERR_TEXT4);
- exit(1);
- }
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 300
- LookAhead */
-
- /* EasyCODE F */
- int LookAhead(FILE* stream, BOOL omit,
- char* delimiter,char* contents,
- int lineNum)
-
- // Reads next line from input file, but resets file pointer
- // to the old position;
- // Delivers ID of keyword of line read ahead;
- {
- long posBefore; /* Position of file pointer before read */
- BOOL bEOF; /* End-of-File flag */
- int ID; /* ID of next keyword */
- if (!omit
- /* Omit indicator is FALSE */)
- {
- posBefore = TellPos(stream);
- bEOF = ReadLine(inbuf,stream);
- /* Get file pointer position and read next line */
- if (bEOF
- /* End-of-File */)
- {
- /* Print error message */
- err_msg(lineNum+1,ERR_TEXT2);
- exit(1);
- }
- else
- {
- /* Reset file pointer and return keyword */
- ID = GetKeyword(delimiter,contents);
- SeekPos(posBefore,stream);
- return (ID);
- }
- }
- else
- {
- /* EasyCODE < */
- return (NO_KEYWORD);
- /* EasyCODE > */
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 378
- main */
-
- /* EasyCODE F */
- void main(int argc, char *argv[])
-
- // Reads lines from the input file and writes them to the
- // output file. Empty lines are skipped. From each line
- // the keyword is extracted using GetKeyword() and the ID
- // is returned. Dependent on the construct (unmodified or
- // to be converted) for each line (keyword) different functions
- // are called.
- {
-
- /* EasyCODE ( 390
- Info */
- // If we have a contruct where the order of subtrees has to be changed
- // the construct has to be processed twice.
- // During the first processing (loop=1) the first subtree is skipped
- // and further subtrees are written. Before the second processing
- // (loop=2) the read pointer is reset to the saved start position(posA)
- // of the first subtree in order to write this subtree. The read pointer
- // is set to the saved end position(posB) afterwards.
- // Depth contains the depth of nestings and is incremented at the start
- // of SEARCH, PERFORMTESTAFTER, PERFORMAFTERVARYING, EXCEPTION
- // and decremented at the corresponding end of the construct.
- // Depth is an index for posA, posB, loop, and the omit indicator.
- // Depth is also incremented at the keyword COBPROGRAMM in order to
- // control the suppression of Divisions using the omit indicator.
- // Furthermore depth is incremented at each LEVEL and decremented
- // at each ENDLEVEL in order to control the limit of levels using the
- // omit indicator again;
- //
- // To write text lines that are not comment lines if the comment option
- // is enabled, "comment" is set to FALSE for that purpose.
- // Sometimes it is necessary to know whether the following subtree
- // contains only DUMMY constructs. This is done by a read ahead
- // provided in the function LookAhead.
- /* EasyCODE ) */
-
- /* EasyCODE ( 391
- Variables */
- int ID; /* ID of actual keyword */
- int i; /* General purpose */
- int ip = -1; /* Position of input file in argument string */
- int op = -1; /* Position of output file in argument string */
- int lineNum = 0; /* Actual line number */
- int lineMem; /* Variable for saving the line number */
- int lines = 1; /* Number of lines in construct header of */
- /* PERFORMTIMES, is passed to addText */
- int levelNum = 0; /* Actual level */
- int maxlevel = MAX_DEPTH; /* Maximum level */
- int depth = 0; /* Actual depth */
- long position; /* Position of read pointer */
-
- char* contents; /* Content of line without keyword+delimiter */
- char* delimiter; /* Delimiter of keyword */
- char* addText; /* Additional Text for next text line */
- char* ignore; /* Keyword to be ignored at next occurence */
- char* numstr; /* Number string containing lines */
-
- FILE* fdr; /* Input file */
- FILE* fdw; /* Output file */
-
- long posA[MAX_DEPTH]; /* Array of start positions */
- long posB[MAX_DEPTH]; /* Array of end positions */
- int loop[MAX_DEPTH]; /* Array of loop indicators */
- BOOL omit[MAX_DEPTH]; /* Array of omit indicators */
- BOOL bEOF = FALSE; /* EOF indicator */
- BOOL comment = FALSE; /* Comment option flag */
- BOOL commem = FALSE; /* General purpose */
- BOOL divisions[4]; /* Array of division suppresions */
- /* EasyCODE ) */
-
- /* EasyCODE ( 392
- Initializations */
- /* Allocate memory for pointers */
- contents = malloc(I_BUFSIZE*sizeof(char));
- delimiter = malloc((MAX_DELIMITERLEN+1)*sizeof(char));
- addText = malloc((MAX_ADDTEXTLEN+1)*sizeof(char));
- ignore = malloc((MAX_KEYWORDLEN+1)*sizeof(char));
- numstr = malloc(4*sizeof(char));
-
- /* Initialize pointers */
- *contents = '\0';
- *delimiter = '\0';
- *addText = '\0';
- *ignore = '\0';
-
- /* Initialize arrays */
- posA[0] = 0;
- posB[0] = 0;
- loop[0] = 0;
- omit[0] = FALSE;
- for (i=0;i<4;i++)
- {
- divisions[i] = TRUE; /* Initialize divisions array */
- }
- for (i=1;i<MAX_DEPTH;i++)
- {
- loop[i] = 1; /* Initialize loop array */
- }
- /* EasyCODE ) */
- /* Check command line parameters */
- check_parms(argc,argv,&ip,&op,&maxlevel,&comment,divisions);
- if (maxlevel == 0)
- {
- maxlevel = MAX_DEPTH;
- }
- /* Open files */
- fdr = OpenInput(argv[ip]);
- fdw = OpenOutput(argv[op]);
- /* EasyCODE - */
- /* Save read position */
- position = TellPos(fdr);
- /* Read first line */
- bEOF = ReadLine(inbuf,fdr);
- /* Increment line number */
- lineNum++;
- while (!bEOF
- /* While not EOF reached */)
- {
- /* Get keyword */
- ID = GetKeyword(delimiter, contents);
- switch (ID
- /* ID of keyword */)
- {
- case ETF_EASYCODE:
- // Only change component indicator,
- // the rest is saved unmodified.
-
- /* EasyCODE ( 401
- Change component indicator to SPX */
-
- /* EasyCODE :
- Change component indicator to SPX */
- {
- char buffer[sizeof(inbuf)+3];
- char *p = NULL;
- /* EasyCODE - */
- // Copy original text to result buffer.
- strcpy (buffer, inbuf);
- if (// Search for delimiter after
- // keyword in buffer.
- p = strpbrk (buffer, "=:;"))
- {
- // If found, go behind delimiter,
- // copy "SPX", and search for delimter
- // in original text (must exist).
- p++;
- strcpy (p, "SPX");
- p = strpbrk (inbuf, "=:;");
- if (// In original text search first
- // blank after delimiter
- // (behind component indicator).
- p = strchr (p, ' '))
- {
- // Add rest of original text
- // to result buffer.
- strcat (buffer, p);
- }
- }
- // Copy buffer back.
- strcpy (inbuf, buffer);
- }
- /* EasyCODE ) */
- StoreUnchanged(fdw, omit[depth], TABLE[ID], ignore);
- break;
- case ETF_SHORTINFO:
- case ETF_ENDSHORTINFO:
- case ETF_OPTIONS:
- case ETF_IFLAYOUT:
- case ETF_LEVELNUMBERS:
- case ETF_LINENUMBERS:
- case ETF_CONSTRUCTNUMBERS:
- case ETF_SCREENFONT:
- case ETF_PRINTERFONT:
- case ETF_LASTLEVELID:
- case ETF_ENDOPTIONS:
- case ETF_IF:
- case ETF_THEN:
- case ETF_ELSE:
- case ETF_ENDIF:
- StoreUnchanged(fdw, omit[depth], TABLE[ID], ignore);
- break;
- case ETF_DUMMY:
- StoreUnchanged(fdw, omit[depth], TABLE[ID], ignore);
- break;
- case ETF_PERFORMTESTBEFORE:
- StoreChanged(fdw, omit[depth], TABLE[ETF_WHILE], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_NOT], delimiter);
- break;
- case ETF_PERFORMTESTBEFOREBODY:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDNOT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_WHILEBODY], delimiter);
- break;
- case ETF_ENDPERFORMTESTBEFORE:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDWHILE], delimiter);
- break;
- case ETF_ONCONDITIONBRANCH:
- case ETF_ONCONDITIONBRANCHBODY:
- case ETF_ENDONCONDITIONBRANCH:
- case ETF_ONSELECTORBRANCH:
- case ETF_ONSELECTORBRANCHBODY:
- case ETF_ENDONSELECTORBRANCH:
- case ETF_TEXT:
- case ETF_ENDTEXT:
- StoreUnchanged(fdw, omit[depth], TABLE[ID], ignore);
- break;
- case ETF_LEVEL:
- // Depth is incremented and therefore a new level created.
- // This also occurs if new level has not been processed
- // (until yet) because it is locked from above.
- // The omit indicator of the new level is initialzed with
- // TRUE. Therefore it is only necessary to check the
- // omit indicator from the higher level instead of checking
- // all omit indicators from all higher levels. (If a level
- // is locked all sublevels are locked, too.
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth+1);
- omit[depth]=TRUE;
- /* EasyCODE - */
- levelNum++;
- /* EasyCODE - */
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- omit[depth]=FALSE;
- /* EasyCODE - */
- // comment set to FALSE for writing the level header.
- /* EasyCODE - */
- commem = comment;
- comment = FALSE;
- if (levelNum > maxlevel)
- {
- // Ignore keyword
- /* EasyCODE - */
- // Just content of level header is written
- /* EasyCODE - */
- ID = LookAhead(fdr,FALSE,delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- Set_ignore(FALSE, ignore, TABLE[ETF_DUMMY]);
- }
- }
- else
- {
- // Whole level is written
- /* EasyCODE - */
- StoreUnchanged(fdw, FALSE, TABLE[ID], ignore);
- }
- }
- break;
- case ETF_LEVELBODY:
- if (!omit[depth-1])
- {
- comment = commem;
- if (levelNum > maxlevel)
- {
- // Ignore keyword
- /* EasyCODE - */
- // Whole level body is ignored - omit indicator set to TRUE
- /* EasyCODE - */
- omit[depth]=TRUE;
- }
- else
- {
- StoreUnchanged(fdw, FALSE, TABLE[ID], ignore);
- }
- }
- break;
- case ETF_ENDLEVEL:
- if (!omit[depth-1])
- {
- if (levelNum > maxlevel)
- {
- // Ignore keyword
- }
- else
- {
- StoreUnchanged(fdw, FALSE, TABLE[ID], ignore);
- }
- }
- // For depth and level have been incremented in either case,
- // whether level construct is precessed including its content
- // or not, both have to be decremented in either case now.
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- /* EasyCODE - */
- levelNum--;
- break;
- case ETF_LINE:
- StoreText(fdw, omit[depth], comment, TABLE[ID], delimiter, addText, contents);
- break;
- case ETF_OFFSET:
- // Ignore keyword "Offset"
- break;
- case ETF_PERFORMBEFOREVARYING:
- StoreChanged(fdw, omit[depth], TABLE[ETF_FRAME], delimiter);
- /* EasyCODE - */
- ID = LookAhead(fdr,omit[depth],delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "PERFORM WITH TEST BEFORE ");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- Set_addText(omit[depth], addText, "VARYING ");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- Set_ignore(omit[depth], ignore, TABLE[ETF_DUMMY]);
- }
- else
- {
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "PERFORM WITH TEST BEFORE ");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- Set_addText(omit[depth], addText, "VARYING ");
- /* EasyCODE - */
- Set_ignore(omit[depth], ignore, TABLE[ETF_TEXT]);
- }
- break;
- case ETF_PERFORMBEFOREVARYINGBODY:
- StoreChanged(fdw, omit[depth], TABLE[ETF_FRAMEBODY], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "");
- break;
- case ETF_ENDPERFORMBEFOREVARYING:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDFRAMEBODY], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, " ");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDFRAME], delimiter);
- break;
- case ETF_PERFORMTESTAFTER:
- // Increment depth, initilize omit indicator
- // with TRUE (see ETF_LEVEL).
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth+1);
- omit[depth]=TRUE;
- /* EasyCODE - */
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- posA[depth] = position;
- }
- else
- {
- omit[depth]=FALSE;
- StoreChanged(fdw, FALSE, TABLE[ETF_UNTIL], delimiter);
- }
- }
- break;
- case ETF_UNTIL:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- omit[depth] = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_REPEAT], delimiter);
- }
- else
- {
- SeekPos(posB[depth],fdr);
- }
- }
- break;
- case ETF_ENDPERFORMTESTAFTER:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- posB[depth] = position;
- loop[depth] = 2;
- SeekPos(posA[depth], fdr);
- lineMem = lineNum;
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- else
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDREPEAT], delimiter);
- /* EasyCODE - */
- lineNum = lineMem;
- *(loop+depth)=1;
- Set_depth(FALSE,&depth,depth-1);
- }
- }
- else
- {
- // Depth has also to be decremented
- // if whole construct was skipped.
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- break;
- case ETF_PERFORMOUTLINE:
- StoreChanged(fdw, omit[depth], TABLE[ETF_CALL], delimiter);
- /* EasyCODE - */
- // comment set to FALSE to always write name
- /* EasyCODE - */
- commem = comment;
- comment = FALSE;
- break;
- case ETF_ENDPERFORMOUTLINE:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDCALL], delimiter);
- /* EasyCODE - */
- comment = commem;
- break;
- case ETF_EXIT:
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "EXIT");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- break;
- case ETF_GOBACK:
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "GOBACK");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- break;
- case ETF_COBPROGRAM:
- // Depth is incremented, omit indicator is
- // initialized with TRUE (see ETF_LEVEL).
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth+1);
- omit[depth]=TRUE;
- break;
- case ETF_IDDIV:
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- if (divisions[0])
- {
- // Identification Division shall be written
- /* EasyCODE - */
- omit[depth] = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_BLOCK], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( FALSE, addText, "IDENTIFICATION DIVISION");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_BLOCKBODY], delimiter);
- }
- else
- {
- // Identification Division shall be suppressed
- /* EasyCODE - */
- omit[depth] = TRUE;
- }
- }
- break;
- case ETF_ENVIRONMENTDIV:
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDBLOCK], delimiter);
- if (divisions[1])
- {
- // Environment Division shall be written
- /* EasyCODE - */
- omit[depth] = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_BLOCK], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( FALSE, addText, "ENVIRONMENT DIVISION");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_BLOCKBODY], delimiter);
- }
- else
- {
- // Environment Division shall be suppressed
- /* EasyCODE - */
- omit[depth] = TRUE;
- }
- }
- break;
- case ETF_DATADIV:
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDBLOCK], delimiter);
- if (divisions[2])
- {
- // Data Division shall be written
- /* EasyCODE - */
- omit[depth] = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_BLOCK], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( FALSE, addText, "DATA DIVISION");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_BLOCKBODY], delimiter);
- }
- else
- {
- // Data Division shall be suppressed
- /* EasyCODE - */
- omit[depth] = TRUE;
- }
- }
- break;
- case ETF_PROCDIVPARAM:
- // comment set to FALSE to always write parameters
- /* EasyCODE - */
- commem = comment;
- comment = FALSE;
- /* EasyCODE - */
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDBLOCK], delimiter);
- if (divisions[3])
- {
- // Procedure Division shall be written
- /* EasyCODE - */
- omit[depth] = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_BLOCK], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( FALSE, addText, "PROCEDURE DIVISION");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- // Look ahaed
- /* EasyCODE - */
- ID = LookAhead(fdr,FALSE,delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- Set_addText( FALSE, addText, "USING <parameter>");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- Set_ignore(FALSE, ignore, TABLE[ETF_DUMMY]);
- }
- else
- {
- Set_ignore(FALSE, ignore, TABLE[ETF_TEXT]);
- /* EasyCODE - */
- Set_addText( FALSE, addText, "USING ");
- }
- }
- else
- {
- // Procedure Division shall be suppressed
- /* EasyCODE - */
- omit[depth] = TRUE;
- }
- }
- break;
- case ETF_PROCDIVBODY:
- comment = commem;
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_BLOCKBODY], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "");
- break;
- case ETF_ENDCOBPROGRAM:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDBLOCK], delimiter);
- /* EasyCODE - */
- // Depth has to be decremented always
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- break;
- case ETF_SECTION:
- // comment set to FALSE to always write name
- /* EasyCODE - */
- commem = comment;
- comment = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_PROCEDURE], delimiter);
- break;
- case ETF_SECTIONBODY:
- comment = commem;
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_PROCEDUREBODY], delimiter);
- break;
- case ETF_ENDSECTION:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDPROCEDURE], delimiter);
- break;
- case ETF_PARAGRAPH:
- // comment set to FALSE to always write name
- /* EasyCODE - */
- commem = comment;
- comment = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_PROCEDURE], delimiter);
- break;
- case ETF_PARAGRAPHBODY:
- comment = commem;
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_PROCEDUREBODY], delimiter);
- break;
- case ETF_ENDPARAGRAPH:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDPROCEDURE], delimiter);
- break;
- case ETF_PERFORMINLINE:
- StoreChanged(fdw, omit[depth], TABLE[ETF_BLOCK], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "PERFORM ");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_BLOCKBODY], delimiter);
- break;
- case ETF_ENDPERFORMINLINE:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDBLOCK], delimiter);
- break;
- case ETF_PERFORMTIMES:
- // Header of construct is processed twice.
- // First time for getting number of text lines.
- // Second time to write text lines an append
- // TIMES to last line
- /* EasyCODE - */
- // Increment depth, initialize omit indicator
- // with TRUE
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth+1);
- omit[depth]=TRUE;
- /* EasyCODE - */
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- posA[depth] = position;
- /* EasyCODE - */
- lineMem = lineNum;
- }
- else
- {
- omit[depth]=FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_FOR], delimiter);
- /* EasyCODE - */
- itoa(lines,numstr,10);
- /* EasyCODE - */
- // Number of text line where TIMES has to
- // be appended is passed;
- /* EasyCODE - */
- strcpy(addText,"<");
- strcat(addText,numstr);
- strcat(addText,">");
- strcat(addText," TIMES");
- }
- }
- break;
- case ETF_PERFORMTIMESBODY:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- loop[depth] = 2;
- SeekPos(posA[depth], fdr);
- lines = lineNum - lineMem - 1 - 3;
- lineMem = lineNum;
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- else
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_FORBODY], delimiter);
- /* EasyCODE - */
- Set_addText(FALSE, addText, "");
- /* EasyCODE - */
- lineNum = lineMem;
- loop[depth]=1;
- Set_depth(FALSE,&depth,depth-1);
- }
- }
- else
- {
- // Depth has also to be incremented if
- // whole construct header was skipped
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- break;
- case ETF_ENDPERFORMTIMES:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDFOR], delimiter);
- break;
- case ETF_PERFORMAFTERVARYING:
- // Increment depth, initialize omit
- // indicator with TRUE
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth+1);
- omit[depth]=TRUE;
- /* EasyCODE - */
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- posA[depth] = position;
- }
- else
- {
- omit[depth]=FALSE;
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDFRAMEBODY], delimiter);
- /* EasyCODE - */
- ID = LookAhead(fdr,FALSE,delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText(FALSE, addText, "VARYING ");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- Set_ignore(FALSE, ignore, TABLE[ETF_DUMMY]);
- }
- else
- {
- Set_addText(FALSE, addText, "VARYING ");
- }
- }
- }
- break;
- case ETF_VARYING:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- omit[depth] = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_FRAME], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText(FALSE, addText, "PERFORM WITH TEST AFTER ");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_FRAMEBODY], delimiter);
- }
- else
- {
- Set_addText( FALSE, addText, "");
- /* EasyCODE - */
- SeekPos(posB[depth],fdr);
- }
- }
- break;
- case ETF_ENDPERFORMAFTERVARYING:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- posB[depth] = position;
- loop[depth] = 2;
- SeekPos(posA[depth], fdr);
- lineMem = lineNum;
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- else
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDFRAME], delimiter);
- /* EasyCODE - */
- lineNum = lineMem;
- loop[depth]=1;
- Set_depth(FALSE,&depth,depth-1);
- }
- }
- else
- {
- // Depth has to be decremented even
- // if whole construct was skipped.
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- break;
- case ETF_EXITPERFORM:
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "EXIT PERFORM");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- break;
- case ETF_EXITTOTEST:
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "EXIT TO TEST");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- break;
- case ETF_EXITPROGRAM:
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "EXIT PROGRAM");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- break;
- case ETF_EXTERNALCALL:
- StoreChanged(fdw, omit[depth], TABLE[ETF_CALL], delimiter);
- /* EasyCODE - */
- // comment set to FALSE to
- // always write name+parameters
- /* EasyCODE - */
- commem = comment;
- comment = FALSE;
- /* EasyCODE - */
- // Look ahead
- /* EasyCODE - */
- ID = LookAhead(fdr,omit[depth],delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "CALL <name>");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- Set_ignore(omit[depth], ignore, TABLE[ETF_DUMMY]);
- }
- else
- {
- Set_addText( omit[depth], addText, "CALL ");
- /* EasyCODE - */
- Set_ignore(omit[depth], ignore, TABLE[ETF_ENDTEXT]);
- }
- break;
- case ETF_EXTERNALCALLPARAM:
- // Look ahead
- /* EasyCODE - */
- ID = LookAhead(fdr,omit[depth],delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- Set_addText( omit[depth], addText, "USING <parameter>");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- Set_ignore(omit[depth], ignore, TABLE[ETF_DUMMY]);
- }
- else
- {
- Set_ignore(omit[depth], ignore, TABLE[ETF_TEXT]);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "USING ");
- }
- break;
- case ETF_ENDEXTERNALCALL:
- comment = commem;
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "");
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDCALL], delimiter);
- break;
- case ETF_SEARCH:
- // Depth will always be incremented, even if
- // SEARCH construct is skipped, in order to
- // keep consistence.
- // Omit indicator of corresponding depth is
- // initialized with TRUE.
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth+1);
- omit[depth]=TRUE;
- /* EasyCODE - */
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- omit[depth] = FALSE;
- StoreChanged(fdw, FALSE, TABLE[ETF_FRAME], delimiter);
- /* EasyCODE - */
- ID = LookAhead(fdr,FALSE,delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( FALSE, addText, "SEARCH <table>");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- Set_ignore(FALSE, ignore, TABLE[ETF_DUMMY]);
- }
- else
- {
- Set_addText(FALSE, addText, "SEARCH ");
- }
- loop[depth] = 1;
- }
- break;
- case ETF_ATEND:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- Set_addText( FALSE, addText, "");
- /* EasyCODE - */
- omit[depth] = TRUE;
- posA[depth] = position;
- }
- else
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_ONCONDITIONREST], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ONCONDITIONBRANCH], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_DUMMY], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ONCONDITIONBRANCHBODY], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_FRAME], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText(FALSE, addText, "AT END ");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_FRAMEBODY], delimiter);
- }
- }
- break;
- case ETF_SEARCHBODY:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- omit[depth] = FALSE;
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_FRAMEBODY], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ONCONDITION], delimiter);
- }
- else
- {
- SeekPos(posB[depth],fdr);
- }
- }
- break;
- case ETF_ENDSEARCH:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- posB[depth] = position;
- loop[depth] = 2;
- SeekPos(posA[depth], fdr);
- lineMem = lineNum;
- }
- else
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDFRAMEBODY], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText(FALSE, addText, " ");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDFRAME], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDONCONDITIONBRANCH], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDONCONDITION], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDFRAMEBODY], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText(FALSE, addText, " ");
- /* EasyCODE - */
- StoreText(fdw, FALSE, comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDFRAME], delimiter);
- /* EasyCODE - */
- lineNum = lineMem;
- /* EasyCODE - */
- loop[depth]=1;
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- }
- else
- {
- // Depth is always decremented
- // even if whole construct was skipped
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- break;
- case ETF_ENTRY:
- // comment set to FALSE to always
- // write name+parameters
- /* EasyCODE - */
- commem = comment;
- comment = FALSE;
- /* EasyCODE - */
- // Look ahaed
- /* EasyCODE - */
- ID = LookAhead(fdr,omit[depth],delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- StoreChanged(fdw, omit[depth], TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "ENTRY <name>");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- Set_ignore(omit[depth], ignore, TABLE[ETF_DUMMY]);
- }
- else
- {
- Set_addText( omit[depth], addText, "ENTRY ");
- /* EasyCODE - */
- Set_ignore(omit[depth], ignore, TABLE[ETF_ENDTEXT]);
- }
- break;
- case ETF_ENTRYUSING:
- // Look ahead
- /* EasyCODE - */
- ID = LookAhead(fdr,omit[depth],delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- Set_addText( omit[depth], addText, "USING <parameter>");
- /* EasyCODE - */
- StoreText(fdw, omit[depth], comment, TABLE[ETF_LINE], "=", addText, contents);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- Set_ignore(omit[depth], ignore, TABLE[ETF_DUMMY]);
- }
- else
- {
- Set_ignore(omit[depth], ignore, TABLE[ETF_TEXT]);
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "USING ");
- }
- break;
- case ETF_ENDENTRY:
- comment = commem;
- /* EasyCODE - */
- Set_addText( omit[depth], addText, "");
- break;
- case ETF_EXCEPTION:
- // Increment depth, initialize omit indicator
- // with TRUE
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth+1);
- omit[depth]=TRUE;
- /* EasyCODE - */
- // Depth was incremented (in either case), therefore the
- // omit indicator of the higher level has to be checked.
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- posA[depth] = position;
- }
- else
- {
- omit[depth]=FALSE;
- StoreChanged(fdw, FALSE, TABLE[ETF_IF], delimiter);
- /* EasyCODE - */
- // comment set to FALSE to always
- // write exception
- /* EasyCODE - */
- commem = comment;
- comment = FALSE;
- }
- }
- break;
- case ETF_ONEXCEPTION:
- if (!omit[depth-1])
- {
- omit[depth] = FALSE;
- if (loop[depth] == 1)
- {
- // Look ahead
- /* EasyCODE - */
- ID = LookAhead(fdr,FALSE,delimiter,contents,lineNum);
- if (ID == ETF_DUMMY)
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_TEXT], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, FALSE, TABLE[ETF_ENDTEXT], delimiter);
- /* EasyCODE - */
- Set_ignore(FALSE, ignore, TABLE[ETF_DUMMY]);
- }
- }
- else
- {
- comment = commem;
- /* EasyCODE - */
- SeekPos(posB[depth],fdr);
- }
- }
- break;
- case ETF_EXCEPTIONBODY:
- if (!omit[depth-1])
- {
- if (loop[depth] == 1)
- {
- posB[depth] = position;
- loop[depth] = 2;
- SeekPos(posA[depth], fdr);
- lineMem = lineNum;
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- else
- {
- StoreChanged(fdw, FALSE, TABLE[ETF_THEN], delimiter);
- /* EasyCODE - */
- lineNum = lineMem;
- loop[depth]=1;
- Set_depth(FALSE,&depth,depth-1);
- }
- }
- else
- {
- // Depth has also to be decremented
- // even if whole construct was skipped
- /* EasyCODE - */
- Set_depth(FALSE,&depth,depth-1);
- }
- break;
- case ETF_NOTEXCEPTIONBODY:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ELSE], delimiter);
- break;
- case ETF_ENDEXCEPTION:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDIF], delimiter);
- break;
- case ETF_EVALUATE:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ONSELECTOR], delimiter);
- break;
- case ETF_EVALUATEBODY:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ONSELECTORLIST], delimiter);
- break;
- case ETF_EVALUATEOTHER:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ONSELECTORREST], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ONSELECTORBRANCH], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_DUMMY], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ONSELECTORBRANCHBODY], delimiter);
- break;
- case ETF_ENDEVALUATE:
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDONSELECTORBRANCH], delimiter);
- /* EasyCODE - */
- StoreChanged(fdw, omit[depth], TABLE[ETF_ENDONSELECTOR], delimiter);
- break;
- case NO_KEYWORD:
- /* Skip empty lines */
- break;
- case ERROR_KEYWORD:
- err_msg(lineNum,ERR_TEXT1);
- /* EasyCODE - */
- exit(1);
- case EOF_KEYWORD:
- err_msg(lineNum,ERR_TEXT2);
- /* EasyCODE - */
- exit(1);
- default:
- err_msg(lineNum,ERR_TEXT3);
- /* EasyCODE - */
- exit(1);
- }
- /* Save read position */
- position = TellPos(fdr);
- /* Read next line */
- bEOF = ReadLine(inbuf,fdr);
- /* Increment line number */
- lineNum++;
- }
- /* Close files */
- CloseFile(fdr);
- CloseFile(fdw);
- }
- /* EasyCODE ) */
- /* EasyCODE ) */
-